package cn.kgc.car.util;

import cn.kgc.car.dao.CarDao;
import cn.kgc.car.dao.UserDao;
import cn.kgc.car.dao.impl.CarDaoImpl;
import cn.kgc.car.dao.impl.UserDaoImpl;
import cn.kgc.car.entity.User;

import java.util.Scanner;

public class Menu {
    Scanner sc=new Scanner(System.in);
    CarDao cars=new CarDaoImpl();
    UserDao users=new UserDaoImpl();
    static User user=null;
    public void mainMenu(){
        do {
            System.out.println("1.注册");
            System.out.println("2.登陆");
            System.out.println("请选择");
            int choice = sc.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入用户名:");
                    String name = sc.next();
                    System.out.println("请输入密码:");
                    String pwd = sc.next();
                    user = new User(name, pwd);
//                  user=users.checkLogin(user);
                    if (users.addUser(user)) {
                        System.out.println("注册成功!");
                    }
                    break;
                case 2:
                    System.out.println("请输入用户名:");
                    name = sc.next();
                    System.out.println("请输入密码:");
                    pwd = sc.next();
                    user=new User(name,pwd);
                    user=users.checkLogin(user);
                    if (user!=null) {
                        System.out.println("登陆成功");
                        do {
                        System.out.println("1.查看系统内所有已出租的车辆信息");
                        System.out.println("2.查看系统内所有未出租的车辆信息");
                        System.out.println("3.输入车牌号查看具体车辆信息");
                        System.out.println("4.租车");
                        System.out.println("5.还车");
                        System.out.println("6.查看租车记录");
                        System.out.println("7.退出系统");
                        System.out.println("请选择");
                        choice = sc.nextInt();
                        switch (choice) {
                            case 1:
                                cars.showRentedCar();
                                break;
                            case 2:
                                cars.showUnRentedCar();
                                break;
                            case 3:
                                System.out.println("请输入你要查询的车牌号:");
                                choice = sc.nextInt();
                                cars.showCar(choice,user);
                                break;
                            case 4:
                                System.out.println("请输入你要租车的车牌号:");
                                cars.showUnRentedCar();
                                choice = sc.nextInt();
                                cars.getCar(choice,user);
                                break;
                            case 5:
                                System.out.println("请输入你要还车的车牌号:");
                                cars.showRentedCar();
                                choice = sc.nextInt();
                                System.out.println("请输入你租车的时间");
                                int time = sc.nextInt();
                                cars.alsoCar(choice, time,user);
                                break;
                            case 6:
                                cars.showUser(user);
                                break;
                            case 7:
                                System.out.println("退出程序，欢迎下次再来");
                                return;
                        }
                        }while (true);
                    } else {
                        System.out.println("用户名或密码错误!");
                    }
            }
        }while (true);
    }
}
